package com.tc.dispatch.csservice.util;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: zju</p>
 * @author jakcyjia
 * @version 1.0
 */
import com.tc.dispatch.csservice.dao.*;
import com.tc.dispatch.csservice.exception.*;
import com.tc.dispatch.csservice.algorithm.CostAlgorithm;
import com.tc.dispatch.csservice.algorithm.calculation.Calclation;
import com.tc.dispatch.csservice.algorithm.bp.BPInterface;
import com.tc.expertsystem.es.ejb.ESServiceLocal;

public class AlgorithmFactory {
  public AlgorithmFactory() {
  }
  public static CostAlgorithm getCostAlgorithm() throws CSSysException {
    try {
      ServiceLocator sl = new ServiceLocator();
      String CSServiceDAOClassName = sl.getString(JNDINames.COST_ALGORITHM_CLASS);
      return (CostAlgorithm) Class.forName(CSServiceDAOClassName).newInstance();
    }
    catch (Exception ex) {
      throw new CSSysException();
    }
  }
  public static Calclation getCalclationAll() throws CSSysException {
      try {
	ServiceLocator sl = new ServiceLocator();
	String CSServiceDAOClassName = sl.getString(JNDINames.CALCLATION_ALL_CLASS);
	return (Calclation) Class.forName(CSServiceDAOClassName).newInstance();
      }
      catch (Exception ex) {
	throw new CSSysException();
      }
    }
    public static Calclation getCalclationYield() throws CSSysException {
	  try {
	    ServiceLocator sl = new ServiceLocator();
	    String CSServiceDAOClassName = sl.getString(JNDINames.CALCLATION_YIELD_CLASS);
	    return (Calclation) Class.forName(CSServiceDAOClassName).newInstance();
	  }
	  catch (Exception ex) {
	    throw new CSSysException();
	  }
	}

	public static BPInterface getBPAlgorithm(ESServiceLocal es) throws CSSysException {
	      try {
		ServiceLocator sl = new ServiceLocator();
		String CSServiceDAOClassName = sl.getString(JNDINames.BP_ALGORITHM_CLASS);
		return (BPInterface) Class.forName(CSServiceDAOClassName).getDeclaredConstructor(Class.forName(CSServiceDAOClassName).getConstructors()[0].getParameterTypes()).newInstance(new Object[]{es});
	      }
	      catch (Exception ex) {
		throw new CSSysException();
	      }
	    }




}